using Autofac;
using Autofac.Integration.Mvc;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

using WebApplication1.Controllers;
using WebApplication1.Servicve;

namespace WebApplication1
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            var builder = new ContainerBuilder();

            builder.RegisterType<Tiger>().As<IAnimal>().AsImplementedInterfaces().InstancePerLifetimeScope();
            builder.RegisterType<Dog>().As<IAnimal2>().AsImplementedInterfaces().InstancePerLifetimeScope();

            builder.RegisterType<Data>().As<IData>().InstancePerDependency();
            //builder.RegisterType<ConvertFileFactory>().As<IConvertFileFactory>().AsImplementedInterfaces().InstancePerLifetimeScope();
            //builder.RegisterType<ConvertFileContext>().InstancePerLifetimeScope();



            builder.RegisterControllers(Assembly.GetExecutingAssembly());
           

            

            //创建一个Autofac的容器
            var container = builder.Build();
            //将MVC的控制器对象实例 交由autofac来创建
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
    }
}
